using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace AzureusWrapper
{
    public class Stats
    {
        public long Downloaded;
        public long Uploaded;
        public long Completed;
        public long DownloadCompletedLive;
        public long DownloadCompletedStored;
        public string Status;
        public long UploadAverage;
        public long DownloadAverage;
        public long ETA;
        public long ShareRatio;
        public string ObjectId;

        public Stats(XmlNode serializedStats)
        {
			string test = serializedStats.InnerXml;

			XmlNodeList list = ((XmlElement)serializedStats).GetElementsByTagName("downloaded");

			this.Downloaded = Int64.Parse(((XmlElement)serializedStats).GetElementsByTagName("downloaded")[0].InnerText.Trim());
			this.Uploaded = Int64.Parse(((XmlElement)serializedStats).GetElementsByTagName("uploaded")[0].InnerText.Trim());
			this.Completed = Int64.Parse(((XmlElement)serializedStats).GetElementsByTagName("completed")[0].InnerText.Trim());
			this.DownloadCompletedLive = Int64.Parse(((XmlElement)serializedStats).GetElementsByTagName("downloadCompletedLive")[0].InnerText.Trim());
			this.DownloadCompletedStored = Int64.Parse(((XmlElement)serializedStats).GetElementsByTagName("downloadCompletedStored")[0].InnerText.Trim());
			this.Status = ((XmlElement)serializedStats).GetElementsByTagName("status")[0].InnerText.Trim();
			this.UploadAverage = Int64.Parse(((XmlElement)serializedStats).GetElementsByTagName("upload_average")[0].InnerText.Trim());
			this.DownloadAverage = Int64.Parse(((XmlElement)serializedStats).GetElementsByTagName("download_average")[0].InnerText.Trim());
			try
			{
				this.ETA = Int64.Parse(((XmlElement)serializedStats).GetElementsByTagName("eta")[0].InnerText.Trim());
			}
			catch { }
			this.ShareRatio = Int64.Parse(((XmlElement)serializedStats).GetElementsByTagName("share_ratio")[0].InnerText.Trim());
			this.ObjectId = ((XmlElement)serializedStats).GetElementsByTagName("_object_id")[0].InnerText.Trim();
        }
    }
}
